package com.cosmoplat.xikai.business.domain.vo.orderTemplate;

import com.cosmoplat.xikai.business.domain.BaseDeliveryInfo;
import com.cosmoplat.xikai.business.domain.BaseDispatchTask;
import com.cosmoplat.xikai.business.domain.dto.mes.ProductionPlanByMesDTO;
import com.cosmoplat.xikai.common.annotation.Excel;
import com.cosmoplat.xikai.common.utils.DateUtils;
import lombok.Data;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassName ProductPlanTemplate
 * @Description 生产计划模板
 * @Version 1.0
 * @Author wdf
 * @Date 2025/1/9
 */
@Data
public class ProductPlanTemplate {

    /**
     * 订单 ==================
     **/
    @Excel(name = "派工单ID")
    private String orderID;

    @Excel(name = "派工单号")
    private String orderNo;

    @Excel(name = "订单-物料ID")
    private String materialIdOrder;

    @Excel(name = "订单-物料编号")
    private String materialCodeOrder;

    @Excel(name = "订单-物料名称")
    private String materialNameOrder;

    @Excel(name = "订单 - 物料规格")
    private String materialSpecOrder;

    @Excel(name = "订单-物料型号")
    private String materialModelOrder;


    /**
     * 订单 ==================
     **/


    /**
     * 任务 ==================
     **/

    @Excel(name = "任务ID")
    private String taskId;

    @Excel(name = "任务号")
    private String taskNo;

    @Excel(name = "工单工序ID")
    private String workOrderProcessId;

    @Excel(name = "工单号")
    private String workOrderNo;

    @Excel(name = "工作中心ID")
    private String workCenterId;

    @Excel(name = "工作中心编号")
    private String workCenterCode;

    @Excel(name = "工作中心名称")
    private String workCenterName;

    @Excel(name = "工序ID")
    private String processId;

    @Excel(name = "工序编号")
    private String processCode;

    @Excel(name = "工序名称")
    private String processName;

    @Excel(name = "任务-物料ID")
    private String materialIdTask;

    @Excel(name = "任务-物料编号")
    private String materialCodeTask;

    @Excel(name = "任务-物料名称")
    private String materialNameTask;

    @Excel(name = "任务-物料型号")
    private String materialModelTask;

    @Excel(name = "计划投产时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
    private String planStartTime;

    @Excel(name = "计划产出时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
    private String planEndTime;

    @Excel(name = "派工数量")
    private BigDecimal dispatchQty;

    @Excel(name = "任务状态")
    private String taskStatus;

    /*@Excel(name = "创建时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
    private String createdAt;

    @Excel(name = "修改时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
    private String modifiedAt;*/

    /**
     * 任务 ==================
     **/

    /**
     * 配料信息 ==================
     **/

    @Excel(name = "备料号")
    private String preparationNo;

    @Excel(name = "配送-物料ID")
    private String materialIdDelivery;

    @Excel(name = "配送-物料编号")
    private String materialCodeDelivery;

    @Excel(name = "配送-物料名称")
    private String materialNameDelivery;

    @Excel(name = "配送 - 物料规格")
    private String materialSpecDelivery;

    @Excel(name = "配送-物料型号")
    private String materialModelDelivery;

    @Excel(name = "所需数量")
    private BigDecimal requiredQty;

    /*@Excel(name = "计划时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
    private String planTime;*/

    @Excel(name = "批次号")
    private String batchNo;

    @Excel(name = "序列号")
    private String serialNo;

    @Excel(name = "配送位置ID")
    private String deliveryPosId;

    @Excel(name = "配送位置编号")
    private String deliveryPosCode;

    @Excel(name = "配送位置名称")
    private String deliveryPosName;

    //工作中心与任务部分的取一样的值


    /**
     * 配料信息 ==================
     **/


    public static List<ProductPlanTemplate> generateProductPlanTemplates (){
        List<ProductPlanTemplate> templates = new ArrayList<>();

        // 示例：创建一条记录，代表一个订单及其相关联的任务和配送信息
        ProductPlanTemplate template = new ProductPlanTemplate();
        template.setOrderID("001");
        template.setOrderNo("ORD001");
        template.setMaterialIdOrder("MAT001");
        template.setMaterialIdTask("Task-MAT001");
        template.setMaterialIdDelivery("Delivery-MAT001");
        template.setMaterialCodeOrder("M001");
        template.setMaterialCodeTask("Task-M001");
        template.setMaterialCodeDelivery("Delivery-M001");
        template.setMaterialNameOrder("物料A");
        template.setMaterialNameTask("物料B");
        template.setMaterialNameDelivery("物料C");
        template.setMaterialSpecOrder("规格X");
        template.setMaterialSpecDelivery("规格Z");
        template.setMaterialModelOrder("型号Z");
        template.setMaterialModelTask("型号Z");
        template.setMaterialModelDelivery("型号Z");
        template.setTaskId("T001");
        template.setTaskNo("TASK001");
        template.setWorkOrderProcessId("WOP001");
        template.setWorkOrderNo("WO001");
        template.setWorkCenterId("WC001");
        template.setWorkCenterCode("WC001");
        template.setWorkCenterName("中心A");
        template.setProcessId("P001");
        template.setProcessCode("PC001");
        template.setProcessName("工序A");
        template.setPlanStartTime("2025-01-10 09:00:00");
        template.setPlanEndTime("2025-01-10 17:00:00");
        template.setDispatchQty(new BigDecimal(10));
        template.setTaskStatus("未开始");
        template.setPreparationNo("PREP001");
        template.setRequiredQty(new BigDecimal(10));
//        template.setPlanTime("2025-01-10 12:00:00");
        template.setBatchNo("BATCH001");
        template.setSerialNo("SERIAL001");
        template.setDeliveryPosId("DP001");
        template.setDeliveryPosCode("DPC001");
        template.setDeliveryPosName("位置A");
        templates.add(template);


        return templates;
    }

    /**
     * 将转换为ProductionPlanByMesDTO对象
     */
    public ProductionPlanByMesDTO copyToProductionPlan() {
        ProductionPlanByMesDTO productionPlan = new ProductionPlanByMesDTO();
        productionPlan.setOrderId(this.orderID);
        productionPlan.setOrderNo(this.orderNo);
        productionPlan.setMaterialId(this.materialIdOrder);
        productionPlan.setMaterialCode(this.materialCodeOrder);
        productionPlan.setMaterialName(this.materialNameOrder);
        productionPlan.setMaterialSpec(this.materialSpecOrder);
        productionPlan.setMaterialModel(this.materialModelOrder);
        return productionPlan;
    }

    /**
     * 将转换为BaseDispatchTask对象
     * @date 13:59 2025/1/9
     * @return com.cosmoplat.xikai.business.domain.BaseDispatchTask
     **/
    public BaseDispatchTask copyToDispatchTask() throws ParseException {
        BaseDispatchTask dispatchTask = new BaseDispatchTask();
        dispatchTask.setOrderId(this.orderID);
        dispatchTask.setTaskId(this.taskId);
        dispatchTask.setTaskNo(this.taskNo);
        dispatchTask.setWorkOrderProcessId(this.workOrderProcessId);
        dispatchTask.setWorkOrderNo(this.workOrderNo);
        dispatchTask.setWorkCenterId(this.workCenterId);
        dispatchTask.setWorkCenterCode(this.workCenterCode);
        dispatchTask.setWorkCenterName(this.workCenterName);
        dispatchTask.setProcessId(this.processId);
        dispatchTask.setProcessCode(this.processCode);
        dispatchTask.setProcessName(this.processName);
        dispatchTask.setPlanStartTime(DateUtils.parseDate(this.planStartTime, DateUtils.YYYY_MM_DD_HH_MM_SS));
        dispatchTask.setPlanEndTime(DateUtils.parseDate(this.planEndTime, DateUtils.YYYY_MM_DD_HH_MM_SS));
        dispatchTask.setDispatchQty(this.dispatchQty);
        dispatchTask.setTaskStatus(this.taskStatus);
        dispatchTask.setCreatedAt(new Date());
        dispatchTask.setModifiedAt(new Date());
        dispatchTask.setMaterialId(this.materialIdTask);
        dispatchTask.setMaterialCode(this.materialCodeTask);
        dispatchTask.setMaterialName(this.materialNameTask);
        dispatchTask.setMaterialModel(this.materialModelTask);
        return dispatchTask;
    }

    /**
     * 将转换为BaseDeliveryInfo对象
     * @date 13:59 2025/1/9
     * @return com.cosmoplat.xikai.business.domain.BaseDeliveryInfo
     **/
    public BaseDeliveryInfo copyToDeliveryInfo() throws ParseException {
        BaseDeliveryInfo deliveryInfo = new BaseDeliveryInfo();
        deliveryInfo.setTaskId(this.taskId);
        deliveryInfo.setMaterialId(this.materialIdDelivery);
        deliveryInfo.setMaterialCode(this.materialCodeDelivery);
        deliveryInfo.setMaterialName(this.materialNameDelivery);
        deliveryInfo.setMaterialSpec(this.materialSpecDelivery);
        deliveryInfo.setMaterialModel(this.materialModelDelivery);
        deliveryInfo.setPreparationNo(this.preparationNo);
        deliveryInfo.setRequiredQty(this.requiredQty);
//        deliveryInfo.setPlanTime(DateUtils.parseDate(this.planTime, DateUtils.YYYY_MM_DD_HH_MM_SS));
        deliveryInfo.setBatchNo(this.batchNo);
        deliveryInfo.setSerialNo(this.serialNo);
        deliveryInfo.setDeliveryPosId(this.deliveryPosId);
        deliveryInfo.setDeliveryPosCode(this.deliveryPosCode);
        deliveryInfo.setDeliveryPosName(this.deliveryPosName);
        deliveryInfo.setTaskId(this.taskId);
        deliveryInfo.setProcessId(this.processId);
        deliveryInfo.setProcessCode(this.processCode);
        deliveryInfo.setProcessName(this.processName);
        deliveryInfo.setWorkCenterId(this.workCenterId);
        deliveryInfo.setWorkCenterCode(this.workCenterCode);
        deliveryInfo.setWorkCenterName(this.workCenterName);
        return deliveryInfo;
    }
}
